//
//  MIDIchooseticketController.m
//  迷笛
//
//  Created by . on 2018/9/14.
//  Copyright © 2018年 🍃🌺🌺🍃. All rights reserved.
//

#import "MIDIchooseticketController.h"
#define Start_X 20.0f           // 第一个按钮的X坐标
#define Start_Y 20.0f           // 第一个按钮的Y坐标
#define Width_Space 20.0f        // 2个按钮之间的横间距
#define Width_Spacee 20.0f        // 2个按钮之间的横间距

#define Height_Space 10.0f      // 竖间距
#define Button_Height 44.0f    // 高
#define Button_Width 156.0f      // 宽
#define Button_Widthh 98.0f      // 宽
#import "MIDIconfirmController.h"
@interface MIDIchooseticketController ()
{
//    UILabel * SHUZI;
}
@property(nonatomic,strong)UILabel * session;
@property(nonatomic,strong)UIButton * sessionBtn;
@property(nonatomic,strong)UILabel * thefare;
@property(nonatomic,strong)UIButton * fareBtn;
@property(nonatomic,strong)UILabel * number;
@property(nonatomic,strong)UILabel * numberYuan;
@property(nonatomic,strong)UILabel * farestate;
@property(nonatomic,strong)UIButton *fBtn;
@property(nonatomic,strong)UILabel * blacklable;
@property(nonatomic,strong)UIButton * Next;
@property(nonatomic,strong)UIButton * add;
@property(nonatomic,strong)UIButton * rome;
//@property(nonatomic,strong)UILabel * SHUZI;




@end

@implementation MIDIchooseticketController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor =[UIColor colorWithHexString:@"#1B212F"];
    
    
    UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithTitle:nil style:UIBarButtonItemStylePlain target:self action:@selector(Block:)];
    self.navigationItem.leftBarButtonItem = leftBarItem;
    
    [self.navigationItem.leftBarButtonItem setImage:[[UIImage imageNamed:@"后退"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

    [self HomeUI];
    [self initButtonMethod];
    [self initButtonMethod2];


}

//视图将要出现时（导航颜色字体颜色）
- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBar.translucent = NO;//Bar的模糊效果，默认为YES

    self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"#171717"];
    self.title = @"选择门票";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#FFFFFF"],NSFontAttributeName : [UIFont fontWithName:@"Helvetica-Bold" size:WidthScale(17)]}];
    //    去掉导航黑线
    UIImage *img = [UIImage imageNamed:@""];
    [self.navigationController.navigationBar setBackgroundImage:img  forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
}
// 返回上一级
-(void)Block:(UIButton * )sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)HomeUI
{
    [self.view addSubview:self.session];
    [self.session mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(kDevice_Is_iPhoneX?HeighX(134):HeightScale(90));
        make.left.mas_offset(WidthScale(20));
    [self.session setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    }];
    [self.view addSubview:self.blacklable];
    [self.blacklable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(kDevice_Is_iPhoneX?HeighX(-34):HeightScale(0));
        make.left.mas_offset(WidthScale(0));
        make.width.mas_offset(WidthScale(240));
        make.height.mas_offset(kDevice_Is_iPhoneX?HeighX(49):HeightScale(49));
    }];
    [self.view addSubview:self.Next];
    [self.Next mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.blacklable);
        make.left.equalTo(self.blacklable.mas_right).offset(WidthScale(0));
        make.width.mas_offset(WidthScale(135));
        make.height.mas_offset(kDevice_Is_iPhoneX?HeighX(49):HeightScale(49));
    }];

}

-(void)initButtonMethod
{
    for (int i = 0 ; i < 3; i++)
    {
        NSInteger index = i % 2;
        NSInteger page = i / 2;
        
        // 圆角按钮
        UIButton *aBt = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//        aBt.frame = CGRectMake(index * (Button_Width + Width_Space) + Start_X, page  * (Button_Height + Height_Space)+Start_Y, Button_Width, Button_Height);
        
        //         x = 排数*(宽+排距)+第一个横坐标;
        //         y = 列数*(高+列距)+第一个纵坐标;
        aBt.layer.cornerRadius = 5;
        //将多余的部分切掉
        aBt.layer.masksToBounds = YES;
        
        //tag标记值
        aBt.tag = i;
        //文字
        NSMutableArray *arry = [[NSMutableArray alloc]initWithObjects:@"2018-09-02-12:00",@"2018-09-02-12:00",@"2018-09-02-12:00",nil];
        [aBt setTitle:arry[i] forState:UIControlStateNormal];
        
        //默认第一个选中
        if (aBt.tag == 0) {
            
            aBt.backgroundColor = [UIColor colorWithHexString:@"#FF005D"];
            [aBt setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
            //定义第一个按钮sender是已经被选中
            _fBtn = aBt;
        }
        else{
            
            aBt.backgroundColor = [UIColor colorWithHexString:@"#666666"];
            [aBt setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
        }
        
        [aBt addTarget:self action:@selector(btnClickMethod:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:aBt];
        [aBt mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.session.mas_bottom).offset(page  * (Button_Height + Height_Space)+Start_Y);
            make.left.mas_offset(WidthScale(index * (Button_Width + Width_Space) + Start_X));
            make.width.mas_offset(WidthScale(Button_Width));
            make.height.mas_offset(kDevice_Is_iPhoneX?HeighX(Button_Height):HeighX(Button_Height));
        }];
        
        [self.view addSubview:self.thefare];
        [self.thefare mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.fBtn.mas_bottom).offset(WidthScale(80));
            make.left.mas_offset(WidthScale(20));
            [self.thefare setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        }];
        
        
    }
}

#pragma mark -- 按钮点击事件
-(void)btnClickMethod:(UIButton *)sender
{
    NSLog(@"点击时间按钮:%ld",(long)[sender tag]);
    
    //点击的和上次是一样的
    if(_fBtn == sender)
    {
        //        //不做处理
    } else{
        
        sender.backgroundColor = [UIColor colorWithHexString:@"#FF005D"];
        [sender setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
        
        _fBtn.backgroundColor = [UIColor colorWithHexString:@"#666666"];
        [_fBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
    }
    _fBtn = sender;
}
-(void)initButtonMethod2
{
    for (int i = 0 ; i < 3; i++)
    {
    
        
        NSInteger index = i % 2;
        NSInteger page = i / 2;
        
        // 圆角按钮
        UIButton *aBt1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        //        aBt.frame = CGRectMake(index * (Button_Width + Width_Space) + Start_X, page  * (Button_Height + Height_Space)+Start_Y, Button_Width, Button_Height);
        
        //         x = 排数*(宽+排距)+第一个横坐标;
        //         y = 列数*(高+列距)+第一个纵坐标;
        aBt1.layer.cornerRadius = 5;
        //将多余的部分切掉
        aBt1.layer.masksToBounds = YES;
        
        //tag标记值
        aBt1.tag = i;
        //文字
        NSMutableArray *arry = [[NSMutableArray alloc]initWithObjects:@"780元 内场",@"780元 内场",@"780元 内场",nil];
        [aBt1 setTitle:arry[i] forState:UIControlStateNormal];
        
        //默认第一个选中
        if (aBt1.tag == 0) {
            
            aBt1.backgroundColor = [UIColor colorWithHexString:@"#FF005D"];
            [aBt1 setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
            //定义第一个按钮sender是已经被选中
            _fBtn = aBt1;
        }
        else{
            
            aBt1.backgroundColor = [UIColor colorWithHexString:@"#666666"];
            [aBt1 setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
        }
        
        [aBt1 addTarget:self action:@selector(btnClickMethod2:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:aBt1];
        [aBt1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.thefare.mas_bottom).offset(page  * (Button_Height + Height_Space)+Start_Y);
            make.left.mas_offset(WidthScale(index * (Button_Widthh + Width_Spacee) + Start_X));
            make.width.mas_offset(WidthScale(Button_Widthh));
            make.height.mas_offset(kDevice_Is_iPhoneX?HeighX(Button_Height):HeighX(Button_Height));
        }];
        [self.view addSubview:self.number];
        [self.number mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.thefare.mas_bottom).offset(WidthScale(130));
            make.left.mas_offset(WidthScale(20));
            [self.number setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        }];
        [self.view addSubview:self.numberYuan];
        [self.numberYuan mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.number.mas_bottom).offset(WidthScale(20));
            make.left.equalTo(self.session);
            [self.numberYuan setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        }];
        [self.view addSubview:self.farestate];
        [self.farestate mas_makeConstraints:^(MASConstraintMaker *make)
         {
            make.top.equalTo(self.number.mas_bottom).offset(WidthScale(20));
            make.left.equalTo(self.numberYuan.mas_right).offset(WidthScale(10));
            [self.farestate setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        }];
        [self.view addSubview:self.rome];
        [self.rome mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.numberYuan);
            make.right.mas_offset(WidthScale(-20));
            make.width.mas_offset(WidthScale(20));
            make.height.mas_offset(kDevice_Is_iPhoneX?HeighX(20):HeightScale(20));
        }];
        SHUZI =[[UILabel alloc]init];
        SHUZI.textColor = [UIColor colorWithHexString:@"FFFFFF"];
        SHUZI.font =[UIFont systemFontOfSize:WidthScale(15)];
        SHUZI.text = @"";
        [self.view addSubview:SHUZI];
        [SHUZI mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.numberYuan);
            make.right.equalTo(self.rome.mas_left).offset(WidthScale(-10));
            make.width.mas_offset(WidthScale(20));
            make.height.mas_offset(kDevice_Is_iPhoneX?HeighX(20):HeightScale(20));
        }];
        [self.view addSubview:self.add];
        [self.add mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.numberYuan);
            make.right.equalTo(SHUZI.mas_left).offset(WidthScale(-15));
            make.width.mas_offset(WidthScale(20));
            make.height.mas_offset(kDevice_Is_iPhoneX?HeighX(20):HeightScale(20));
        }];
        
//        Button_Widthh
    }
}

#pragma mark -- 按钮点击事件
-(void)btnClickMethod2:(UIButton *)sender
{
    NSLog(@"点击时间按钮:%ld",(long)[sender tag]);
    
    //点击的和上次是一样的
    if(_fBtn == sender)
    {
        //        //不做处理
    } else{
        
        sender.backgroundColor = [UIColor colorWithHexString:@"#FF005D"];
        [sender setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
        
        _fBtn.backgroundColor = [UIColor colorWithHexString:@"#666666"];
        [_fBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
    }
    _fBtn = sender;
}







-(UILabel *)session
{
    if (!_session)
    {
        _session =[[UILabel alloc]init];
        _session.text = @"场次";
        _session.textColor =[UIColor whiteColor];
        _session.font =[UIFont systemFontOfSize:WidthScale(15)];
    }
    return _session;
}
-(UILabel *)thefare
{
    if (!_thefare)
    {
        _thefare = [[UILabel alloc]init];
        _thefare.text = @"票价";
        _thefare.textColor =[UIColor whiteColor];
        _thefare.font =[UIFont systemFontOfSize:WidthScale(15)];
    }
    return _thefare;
}
-(UIButton *)fBtn
{
    if (!_fBtn)
    {
        _fBtn =[UIButton buttonWithType:UIButtonTypeRoundedRect];
    }
    return _fBtn;
}
-(UILabel *)number
{
    if (!_number)
    {
        _number =[[UILabel alloc]init];
        _number = [[UILabel alloc]init];
        _number.text = @"数量";
        _number.textColor =[UIColor whiteColor];
        _number.font =[UIFont systemFontOfSize:WidthScale(15)];
    }
    return _number;
}
-(UILabel *)numberYuan
{
    if (!_numberYuan)
    {
        _numberYuan = [[UILabel alloc]init];
        _numberYuan.text = @"780元";
        _numberYuan.textColor =[UIColor whiteColor];
        _numberYuan.font =[UIFont systemFontOfSize:WidthScale(15)];
    }
    return _numberYuan;
}
-(UILabel *)farestate
{
    if (!_farestate)
    {
        _farestate = [[UILabel alloc]init];
        _farestate.text = @"内场";
        _farestate.textColor =[UIColor whiteColor];
        _farestate.font =[UIFont systemFontOfSize:WidthScale(15)];
    }
    return _farestate;
}
-(UILabel *)blacklable
{
    if (!_blacklable)
    {
        _blacklable = [[UILabel alloc]init];
        _blacklable.text = @"780元";
        _blacklable.textColor =[UIColor whiteColor];
        _blacklable.backgroundColor =[UIColor blackColor];
        _blacklable.textAlignment = NSTextAlignmentCenter;
        _blacklable.font =[UIFont systemFontOfSize:WidthScale(20)];
    }
    return _blacklable;
}
-(UIButton *)Next
{
    if (!_Next)
    {
        _Next =[[UIButton alloc]init];
        [_Next setBackgroundColor:[UIColor colorWithHexString:@"#FF005D"]];
        [_Next setTitle:@"下一步" forState:UIControlStateNormal];
        [_Next addTarget:self action:@selector(Next:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _Next;
}
-(void)Next:(UIButton * )sender
{
    MIDIconfirmController * confirm =[[MIDIconfirmController alloc]init];
    [self.navigationController pushViewController:confirm animated:YES];
}



-(UIButton *)add
{
    if (!_add)
    {
        _add =[[UIButton alloc]init];
        [_add setBackgroundColor:[UIColor grayColor]];
        [_add setTitle:@"+" forState:UIControlStateNormal];
        [_add setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
        [_add addTarget:self action:@selector(Add) forControlEvents:UIControlEventTouchUpInside];
    }
    return _add;
}
-(UIButton *)rome
{
    if (!_rome)
    {
        _rome =[[UIButton alloc]init];
        [_rome setBackgroundColor:[UIColor colorWithHexString:@"#666666"]];
        [_rome setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
        [_rome setTitle:@"-" forState:UIControlStateNormal];
        [_rome addTarget:self action:@selector(Rome) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rome;
}
//-(UILabel *)SHUZI
//{
//    if (!_SHUZI)
//    {
//        _SHUZI =[[UILabel alloc]init];
//        _SHUZI.textColor = [UIColor colorWithHexString:@"FFFFFF"];
//        _SHUZI.font =[UIFont systemFontOfSize:WidthScale(15)];
//        _SHUZI.text = @"0";
//    }
//    return _SHUZI;
//}
-(void)Add
{
    labelNumber++;
    SHUZI.text = [NSString stringWithFormat:@"%d",labelNumber ];
}
-(void)Rome
{
    labelNumber--;
    SHUZI.text = [NSString stringWithFormat:@"%d",labelNumber ];
}
@end
